<template>
	<div class="content">
    <law-order-nav style="z-index: 999;" title="预约地点" :choose="true" @chooseAddress="chooseAddress"></law-order-nav>

    <!--#ifdef H5-->
<!--		<web-view src="https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=	DH4BZ-EDEWR-RULWZ-WNUWB-HNAKQ-KJB7Q&referer=myapp" @message="onMessage"></web-view>-->
		<!--#endif-->
<!--    &lt;!&ndash; #ifdef H5 &ndash;&gt;-->
<!--    <view class="" id="map1" ref="map1" style="width: 100%; height: 600rpx;"></view>-->
<!--    &lt;!&ndash; #endif &ndash;&gt;-->

    <law-amap-choose ref="chooseMap" :color="color" :keyMap="keyMap" :AMapKeyWeb="AMapKeyWeb" :show="show" :initLocation="initLocation" :initLocationall="initLocationall" @placeChoose="placeChoose" @changeShow="changeShow"></law-amap-choose>
		<!-- 全局通用组件 -->
		<law-common ref="lawCommon"></law-common>
	</div>
</template>

<script>
export default {
	data() {
		return {
			height: uni.getSystemInfoSync().screenHeight,
      color:'#FFC801',
      keyMap:'a8495fcc75776a9eb1a4f3e907f0b84e',
      AMapKeyWeb:'5e0d711dc520a746549847425fc5465f',
      show:true,
      initLocation:'',
      address:'',
      initLocationall:''
		};
	},
  onLoad: function(e) {
		var that = this;
    if(uni.getStorageSync('forwardLocation')){
	    let orginAddress =  JSON.parse(uni.getStorageSync('forwardLocation'))
	    that.initLocation = orginAddress.longitude+','+orginAddress.latitude;
	    that.initLocationall = orginAddress
        console.log("=====uni.getStorageSync('forwardLocation'):",JSON.parse(uni.getStorageSync('forwardLocation')), that.initLocation)
    }
  },
	onReady() {
		const self = this;
		//#ifdef H5
		if (window.isListen) {
			// 防止多次注册addEventListener事件
			return;
		}
		window.addEventListener(
			'message',
			function(event) {
				var loc = event.data;
				if (loc && loc.module == 'locationPicker') {
					self.getPositon(loc, self);
				}
				window.isListen = true;
				window.removeEventListener('message', function() {}, true);
			},
			false
		);
		//#endif
	},
	methods: {
	    chooseAddress(){
	      this.$refs.chooseMap.confrom()
	    },
		// onMessage(res) {
		// 	console.log('app接收网页消息:', res.detail.data[0]);
		// 	this.getPositon(res.detail.data[0], this);
		// },
		getPositon(res, self) {
			let pages = getCurrentPages();
			let prePage = pages[pages.length - 2];
			prePage.$vm.onAddressChange(res);
      console.log("================res",res)
      uni.navigateBack({
        delta:1
      })
		},
    gdLcation(){
      this.show = true
    },
    placeChoose(val){
      this.address = val.address;
      this.getPositon(val, this);
    },
    changeShow(val){
      console.log(val)
    }
	}
};
</script>

<style scoped lang="scss"></style>
